export const PageMixin = {
  data() {
    return {
      data: {
        pageSize: 10,
        currentPage: 1,
        count: 0,
        totalPages: 0,
        data: []
      }
    };
  },
  computed: {
    page() {
      const { data } = this;
      return {
        pageSize: data.pageSize || 10,
        pageNum: data.currentPage || 1,
        total: data.count || 0
      };
    }
  },
  methods: {
    refresh() {
      this.getData();
    },
    pageChange(page) {
      this.data.currentPage = page;
      this.getData();
    },
    calculatePage(type = "-") {
      let { count } = this.data;
      const { totalPages, pageSize, currentPage } = this.data;
      if (type === "-") {
        count--;
        if (count > 0 && count % pageSize === 0 && totalPages === currentPage) {
          this.data.currentPage--;
        }
      }
    }
  }
};
